﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using XML_Programming_Assignment.Class;
using System.Collections;

namespace XML_Programming_Assignment
{
    public partial class FrmRFQValidation : Form
    {
        static bool checkValid = false;
        static string filepath = null;

        public FrmRFQValidation()
        {
            InitializeComponent();
        }

        private void MainMenu_toolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Hide();
            AllFormClass.formDefault.Show();
        }

        private void ReadQuotation_toolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Hide();
            AllFormClass.formReadQuotation.Show();
        }

        private void Validate_toolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Hide();
            AllFormClass.formRFQValidation.Show();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("David Computer Service Pte Ltd" + "\r\n" + "Supply Chain Management System" + "\r\n" + "Developed By" + "\r\n" + "Sithu Kyaw", "Version", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void notepadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("Notepad.exe");
        }

        private void calculatorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("calc");
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {           
            dialogXMLOpen.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
            dialogXMLOpen.Title = "Select an XML file";            

            if (dialogXMLOpen.ShowDialog() == DialogResult.OK)
            {
                tbxFilePath.Clear();
                filepath = dialogXMLOpen.FileName;
                tbxFilePath.Text = filepath;
                //checkValid = DBManager.validateXml(filepath);               
            }
        }

        private void btnValidate_Click(object sender, EventArgs e)
        {
            tbxResult.Clear();

            bool checkValidate = false;
            checkValid = DBManager.validateXml(filepath);
            tbxResult.Text += "Start Validating....." + "\r\n" + "\r\n";

            if (checkValid)
            {
                MessageBox.Show("Validation is Successful", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                tbxResult.Text += "File has been vaildated with the schema successfully";
            }
            else
            {
                MessageBox.Show("Validation is Fail", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);

                tbxResult.Text += "Validation Errors" + "\r\n";
                tbxResult.Text += "------------------------------" + "\r\n";
                foreach (string error in AllFormClass.validateErrorList)
                {
                    tbxResult.Text += error + "\r\n";
                }
                tbxResult.Text += "\r\n" + "----------- Tips : The schema file must be in the same directory or folder with the XML file to be validated-----------";

            }
        }

        private void FrmRFQValidation_Activated(object sender, EventArgs e)
        {
            tbxFilePath.Text = "";
            tbxResult.Clear();
        }

        
    }
}
